package com.project.internship.controller.base;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.internship.entity.Audit;
import com.project.internship.entity.resp.RespBean;
import com.project.internship.entity.resp.RespPageBean;
import com.project.internship.service.AuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/base/audit")
public class BaseAuditController {

    @Autowired
    AuditService auditService;

    /**
     * 获得审核信息
     * @param current
     * @param size
     * @param status 审核状态  0 待审核  1 审核通过  2  审核未通过
     * @param keyword
     * @return
     */
    @GetMapping("/")
    public RespPageBean getAudit(@RequestParam(defaultValue = "1") Integer current,
                                 @RequestParam(defaultValue = "10") Integer size,
                                 Integer status, String keyword){
        Page<Audit> page = new Page<>(current,size);

        Long total = auditService.getAudit(page, status, keyword).getTotal();
        List<Audit> data = auditService.getAudit(page, status, keyword).getRecords();

        return new RespPageBean(total, data);
    }

    @PutMapping("/success")
    public RespBean setAuditSuccess(@RequestBody Audit audit){
        if(auditService.setAuditSuccess(audit) == 1) {
            return RespBean.ok("审核通过！");
        }
        return RespBean.ok("审核通过失败！");
    }

    @PutMapping("/fail")
    public RespBean setAuditFail(@RequestBody Audit audit){
        if(auditService.setAuditFail(audit) == 1) {
            return RespBean.ok("审核未通过！");
        }
        return RespBean.ok("审核未通过失败！");
    }

}
